! ! Up2Caps.txt for Clarion Database Developers using CDD 3 ! ! ! This is an example of How to change UPPERCASE strings into Lowercase ! strings that have a capital letter as the first letter. (Caps) ! ie: 'NEW YORK CITY' will change into 'New York City' ! Use the BATCH template! ! ! I used this bit of source to change the city field records in a ! zipcode database from uppercase to lower case by placing this ! code in the "Within LOOP" embed area of a BATCH procedure template ! then running the Batch. (Press the Files Button and add Zipcode, ! make this a Change procedure in the procedure properties window.) ! This will handle any records that are less then "3 words" automatically ! for you without changing the code, ie: 'FORT LAUDERDALE' becomes ! 'Fort Lauderdale', since in effect this code looks for a string, finds ! the end of the "word" by locating a trailing space, counts the "letters" ! of the "word" from the space backwards to the beginning of the "word" ! and subtracts 1 from the count to determine the amount of "letters" to ! convert to lower case then the new word is created by concatenating ! the first "letter" with the new lower case "letters". The process is ! repeated for a second "word" in the string if one exists and then a ! third "word" if one exists. The final step is to concatenate the ! "words" to replace the old record ie:'NEW YORK CITY' with 'New York City'. ! ! The Following Field Variables located in the EMBED Code are to be replaced ! with your own. ! ! Zip:City - (11 instances) This is the field name that will contain ! the records of the strings to be converted, ie: change it to Pre:Fieldname ! ie: You:YourOwnFieldName ! ! All the other variables can stay the same (I used implicit variables ! to keep things simple). ! ! This is the code : OMIT('Ό') ΙΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝ» Ί ChangeCityCaseZipCd - (Change City Field Case From Upper to Caps ) - Batch Ί Ί Screen Structure Defined Ί Ί PullDown Structure NOT Defined Ί Ί Report Structure NOT Defined Ί Ί Primary File: Zipcode ! Primary Processing File Ί ΘΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΝΌ ChangeCityCaseZipCd PROCEDURE RecordCounter LONG ScreenTitle STRING(30) StatusString STRING(40) Zip::Opened BYTE ! TRUE is PROC opens file SCREEN SCREEN(7,46),PRE(SCR),SHADOW,FALL,CUA,COLOR(1) ROW(1,1) STRING('Ϋ{8}'),COLOR(113) COL(39) STRING('Ϋ{8}'),COLOR(113) ROW(7,1) STRING('Ϋά{44}Ϋ'),COLOR(113) REPEAT(5) ROW(2,1) STRING('Ϋ'),COLOR(113) ROW(2,46) STRING('Ϋ'),COLOR(113) . ROW(1,9) ENTRY(@s30),USE(ScreenTitle),OVR,SKIP,COLOR(19,9,38) ROW(3,4) ENTRY(@s40),USE(StatusString),OVR,SKIP,COLOR(8,9,38) ROW(5,14) BUTTON(' &Ok '),SHADOW,KEY(EnterKey),USE(?Ok),COLOR(17,18,39,19,20) COL(26) BUTTON(' &Cancel '),SHADOW,KEY(EscKey),USE(?Cancel),COLOR(17,18,39,19,20) . CODE EMBED('~~ChangeCityCaseZipCd~1~Setup Procedure~3~~') ! **EMBED to IDLE() ! Temporarily Turn off any ! IDLE Procedure ENDEMBED Zip::Opened = CheckOpen(Zipcode) ! Open file if necessary ScreenTitle = CENTER('Updating Zipcode Records',LEN(ScreenTitle)) !Assign title StatusString = CENTER('Select Ok to Process Records',LEN(StatusString)) OPEN(Screen) !Open the screen DISPLAY LOOP CASE SELECTED() !Jump to field setup routine END !End CASE ACCEPT !Enable the mouse and keyboard CASE FIELD() !Jump to field edit routine OF ?Ok !On the OK button BREAK OF ?Cancel !On Cancel button DO ProcedureReturn END !End CASE END !End LOOP DISABLE(?Ok) !Disable the Ok and DISABLE(?Cancel) ! cancel buttons SET(Zip:CityKey) RecordCounter = 0 DISPLAY LOOP NEXT(Zipcode) EMBED('~~ChangeCityCaseZipCd~1~NEXT Record Error Check~5~~') IF ERRORCODE() THEN BREAK. ENDEMBED EMBED('~~ChangeCityCaseZipCd~1~Within LOOP~5~~') ! **EMBEDED SOURCE CODE STARTS HERE Loc:1stSpcStepNo# = INSTRING(' ',Zip:City,1,1) ! Find the first space location then Loc:1stLowCaseLen# = Loc:1stSpcStepNo# - 2 ! Subtract 1 for the space and 1 from the word to find the length of the part to change to lower case Loc:1stLowCaseName" = SUB(Zip:City,1,1) & LOWER(SUB(Zip:City,2,Loc:1stLowCaseLen#)) ! Concatenate the Field first letter with the Field starting at the second letter location for the length of Loc:1stLowCaseLen# Loc:2ndSpcStepNo# = INSTRING(' ',Zip:City,1,(Loc:1stSpcStepNo# + 1)) Loc:2ndLowCaseLen# = Loc:2ndSpcStepNo# - (Loc:1stSpcStepNo# + 2) Loc:2ndLowCaseName" = SUB(Zip:City,(Loc:1stLowCaseLen# + 3),1) & LOWER(SUB(Zip:City,(Loc:1stLowCaseLen# + 4),Loc:2ndLowCaseLen#)) Loc:3rdSpcStepNo# = INSTRING(' ',Zip:City,1,(Loc:2ndSpcStepNo# + 1)) Loc:3rdLowCaseLen# = Loc:3rdSpcStepNo# - (Loc:2ndSpcStepNo# + 2) Loc:3rdLowCaseName" = SUB(Zip:City,((Loc:1stLowCaseLen# + Loc:2ndLowCaseLen#) + 5),1) & LOWER(SUB(Zip:City,((Loc:1stLowCaseLen# + Loc:2ndLowCaseLen#) + 6),Loc:3rdLowCaseLen#)) Zip:City = Clip(Loc:1stLowCaseName") & ' ' & Clip(Loc:2ndLowCaseName") & ' ' & Clip(Loc:3rdLowCaseName") Show(1,1,CENTER(Zip:City,80)) ! **ENDS HERE ENDEMBED PUT(Zipcode) EMBED('~~ChangeCityCaseZipCd~1~PUT/DELETE Record Error Check~5~~') IF ERRORCODE() THEN STOP(ERROR()). ENDEMBED RecordCounter += 1 StatusString = CENTER(RecordCounter & ' Records Changed',LEN(StatusString)) DISPLAY(?StatusString) END DO ProcedureReturn !ΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔ ProcedureReturn ROUTINE IF Zip::Opened THEN CLOSE(Zipcode). ! IF opened, close file DO EndOfProcedureEmbed RETURN !ΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔΔ EndOfProcedureEmbed ROUTINE ! ! Hope someone finds this useful ! Any questions? - Direct them to David Rodriguez on the Fido Net ! Clarion Conference Area ! My address is 5456 NW 1st Avenue, Fort Lauderdale, FL 33309 ! ! ** Before you use this on your .dat files, make sure you BACKUP your ! files! ie: Copy zipcode.dat zipbak.dat ! Run the batch, and if the power goes out or something, you won't be ! sorry. ! ! P.S. Run this code in the VID and step thru a few records ! then press ALT-F5 to Display Local Variables (or you can ! use the display menu) so you can see how the strings change. ! ! *** Note *** This is not a complete program, it's just a Batch template ! procedure. You will have to incorporate it into any program ! in which you intend for it to run. ! It is a complete Batch Procedure. ! ! There may be other ways to accomplish this, but I didn't find one. ! (besides this works!) ! ! Ref: Clarion Database Developer Language Reference ! String Functions starting on Page 13-9 ! See INSTRING on Page 13-12